< previous page page_13 next page >

Page 13
rior. If you look very closely at Figure 1.5, you will see that one pixel was cropped off the right and bottom corners of the first diamond in the program BoxSize.
To prevent this problem, you can make your coordinate system slightly larger to provide a small margin around whatever you are drawing. For example, you can add one pixel's worth of room when you calculate Width and Height. In the code above, you would set the values of extra_wid and extra_hgt as shown here:
e10a6a0a59f035e870d90cca05b85fce.gif
extra_wid = .Width - _
    Me.ScaleX(ScaleWidth, .ScaleMode, Me.ScaleMode) + _
    Me.ScaleX(1, vbPixels, Me.ScaleMode)
extra_hgt = .Height - _
    Me.ScaleY(.ScaleHeight, .ScaleMode, Me.ScaleMode) + _
    Me.ScaleY(1, vbPixels, Me.ScaleMode)
The Move Method
Forms and controls provide a Move method that allows you to set the Top, Left, Width, and Height properties all at once. The syntax for the Move method is:
object.Move left, top, width, height
Here, object is the object you want to move, and left, top, width, and height are the new values you want to set for the Left, Top, Width, and Height properties. Not only does this method save you a little coding, it is also quite a bit faster. Each time you change one of these four properties, Visual Basic must move or resize the control and redraw it. If you change all four of these values separately, Visual Basic redraws the control four times. If you use the Move method, Visual Basic redraws the control only once. In tests, using the Move method works almost four times as fast as changing the four properties individually.
Only the Move method's first argument, left, is required. You can leave other arguments off if you do not need to change them. For example, you can specify only the left and top values to move the control without resizing it.
Graphic Container Controls
Three kinds of objectsforms, picture boxes, and printer objectscan supply most of your graphic needs. Forms are the largest unit in a typical Visual Basic user interface. You can draw directly on a form, and forms can contain other controls. A form can have different kinds of ''window decoration," including a title bar, system menu, buttons, and resizable borders.
As with forms, you can draw directly on a picture box. You can also place other controls within a picture box. While you can draw directly on a form, it is more common to place one or more picture boxes on the form and then draw on those. This approach takes a bit more memory but provides extra flexibility. If you decide to move a drawing to another part of the form, for example, you can simply move the picture box to a new

 
< previous page page_13 next page >